﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using 请求响应加密.Attr;
using 请求响应加密.Tools.Encrypt;

namespace 请求响应加密.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Permission("Admin:Read,Admin:Write")]
    public class PermissionController : ControllerBase
    {
        [Route("PermRead")]
        [HttpGet]
        public ActionResult<string> PermRead()
        {
            return "当前用户具有读取的权限";
        }


        [Route("PermWrite")]
        [HttpGet]
        public ActionResult<string> PermWrite()
        {
            return "当前用户具有写入的权限";
        }

        [Route("Update")]
        [HttpGet]
        [Permission("Admin:Update")]
        public ActionResult<string> PermUpdate()
        {
            return "当前用户具有更新的权限";
        }

        [Route("Delete")]
        [HttpGet]
        [Permission("Admin:Delete")]
        public ActionResult<string> PermDelete()
        {
            return "当前用户具有删除的权限";
        }

        [Route("CreateRSAKey")]
        [HttpGet]
        [Permission("Admin:Write")]
        public ActionResult<string> CreateRSAKey()
        {
            EncryptHelper.GeneratePubPriKey(out string pubKey, out string prKey);
            return $"pubkey: {pubKey}\nprKey: {prKey}";
        }

    }
}
